import './public-path';
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import App from './App.vue'
import routes from './router/'

let instance = null
let router = null

router = createRouter({
    history: createWebHistory(window.__POWERED_BY_QIANKUN__ ? '/vue3-app-tm/' : '/'),
    routes
})

function render(props = {}) {
    const { container } = props;
    instance = createApp(App)
    instance.use(router).mount(container ? container.querySelector('#app') : '#app')
  }
  
  // when run independently
  if (!window.__POWERED_BY_QIANKUN__) {
    render();
  }
  
  export async function bootstrap() {
    console.log('[vue] vue app bootstraped');
  }
  export async function mount(props) {
    console.log('[vue] props from main framework', props);
    render(props);
  }
  export async function unmount() {
    // vue3修改$destoryed为unmount
    instance.unmount();
    instance._container.innerHTML = '';
    instance = null;
  }